package cn.com.dycc.util;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import cn.com.dycc.sys_manage.deptsysmanagement.entity.Dept;


/**
 * 
 * Description: 部门树返回工具类
 * Author: linfangan
 * Version: 1.0
 * Create Date Time: 2017年8月21日 9:29:18.
 * Update Date Time: 
 * @see
 */
public class DeptTree {
	
	public static Map<String,Object> mapArray = new LinkedHashMap<String, Object>();
	public List<Dept> deptCommon; 
	public List<Object> list = new ArrayList<Object>(); 
	
	public List<Object> deptList(List<Dept> dept,String topPid,String send_dept_id){ 
		this.deptCommon = dept;
		for(Dept x : dept){
			Map<String,Object> mapArr = new LinkedHashMap<String, Object>();
			if(topPid.equals(x.getPid())){
				mapArr.put("id",x.getDept_no());
				mapArr.put("name",x.getDept_name());
//				mapArr.put("dept_info",x.getDept_info());
				mapArr.put("pid",x.getPid());
//				mapArr.put("hidden",x.getHidden());
//				mapArr.put("area_id",x.getArea_id());
//				mapArr.put("dept_addr",x.getDept_addr());
//				mapArr.put("dept_tel",x.getDept_tel());
//				mapArr.put("dept_tel",x.getDept_tel());
//				mapArr.put("order_no",x.getOrder_no());
//				mapArr.put("remark",x.getRemark());
				mapArr.put("open","true");
				//默认选中
				if(send_dept_id!=null&&send_dept_id.equals(x.getDept_no())){
					mapArr.put("checked","true");
				}
				//子部门
				mapArr.put("children",children(x.getDept_no(),send_dept_id));
				list.add(mapArr);
			}
		}
		return list;
	}
	
	 public List<?> children(String deptNo,String send_dept_id){
		 List<Object> lists = new ArrayList<Object>();
		 for(Dept a:deptCommon){
			 Map<String,Object> childArray = new LinkedHashMap<String, Object>();
			 if(deptNo.equals(a.getPid())){
				 childArray.put("id",a.getDept_no());
				 childArray.put("name",a.getDept_name());
//				 childArray.put("dept_info",a.getDept_info());
				 childArray.put("pid",a.getPid());
//				 childArray.put("hidden",a.getHidden());
//				 childArray.put("area_id",a.getArea_id());
//				 childArray.put("dept_addr",a.getDept_addr());
//				 childArray.put("dept_tel",a.getDept_tel());
//				 childArray.put("order_no",a.getOrder_no());
//				 childArray.put("remark",a.getRemark());
				 childArray.put("open","true");
				//默认选中
				 if(send_dept_id!=null&&send_dept_id.equals(a.getDept_no())){
					 childArray.put("checked","true");
					}
				//子部门
				 childArray.put("children",children(a.getDept_no(),send_dept_id));
				 lists.add(childArray);
			 }
		 }
		 return lists;
	 }
}
